<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <ul>
        <li v-for="(item,index) in jieshoulist" :key="index">
          {{item}}
        </li>
      </ul>
      <h1>{{jieshoustr}}</h1>
      <hr />
      <zi-com @sdata="getdata"></zi-com>
    </div>
    <template id="zi">
      <div>
        <h1>我是子组件</h1>
        <button @click="send">传递数据</button>
      </div>
    </template>
    <script src="vue.js"></script>
    <script>
      // 自定义事件传值
      //子组件绑定自定义事件
      //子组件内部用this.$emit('事件名'，传送的数据，传送的数据)
      //父组件内部的事件函数的形参 就是传来的数据
      var vm = new Vue({
        el: '#app',
        data() {
          return {
            jieshoulist: [],
            jieshoustr: ''
          }
        },
        methods: {
          getdata(a, b) {
            console.log(a, b)
            this.jieshoulist = a
            this.jieshoustr = b
          }
        },
        components: {
          ziCom: {
            template: '#zi',
            data() {
              return {
                list: ['春天', '下天', '邱天', '东天'],
                mystr: '后天放假'
              }
            },
            mounted() {
              this.$emit('sdata', this.list, this.mystr)
            },
            methods: {
              send() {
                console.log(111111)
                // 触发父组件的自定义事件并传值
                this.$emit('sdata', this.list, this.mystr)
              }
            }
          }
        }
      })
    </script>
  </body>
</html>
